﻿CREATE PROCEDURE admin.s_HelpPKs
	@TableName sysname,
	@Html xml OUT
AS            
SET @Html = NULL
DECLARE @PKs TABLE(TABLE_QUALIFIER	sysname,TABLE_OWNER	sysname,TABLE_NAME	sysname,COLUMN_NAME	sysname,KEY_SEQ	smallint,PK_NAME	sysname)
INSERT INTO @PKs
exec sp_pkeys @TableName

IF NOT EXISTS(SELECT * FROM @PKs )RETURN

SELECT @Html =(
SELECT 
1 '@border',
(select 
(select 'Primary Key Column' for xml path('th'),type),
(select 'Key Name' for xml path('th'),type)
for xml path('tr'),type,root('thead')),
(
(
SELECT 
(select COLUMN_NAME+'' for xml path('td'),type),
(select PK_NAME+'' for xml path('td'),type)
FROM @PKs for xml path('tr'),type
)

)
 for xml path('table'),type)


